Add new MissingTryBlock rule#2179
Conversation
|
👋 This rule has a severity of This has the same copy-pasta as your other PR. |
…in the rule definition and resolved copy-pasta in the rule description. Co-authored-by: Copilot <copilot@github.com>
…m Error to Warning.
There was a problem hiding this comment.
Pull request overview
Adds a new built-in PSScriptAnalyzer rule to detect catch/finally blocks used without a preceding try, with accompanying documentation and Pester tests to validate behavior.
Changes:
- Introduces the new
MissingTryBlockbuilt-in rule implementation and localized strings. - Adds rule documentation and registers it in the rules documentation index.
- Adds a dedicated Pester test suite for violation, compliant, and suppression scenarios.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| docs/Rules/README.md | Adds MissingTryBlock to the published rules index table. |
| docs/Rules/MissingTryBlock.md | New rule documentation page describing intent, guidance, and examples. |
| Tests/Rules/MissingTryBlock.tests.ps1 | New Pester coverage for violations, compliant cases, and suppression behavior. |
| Rules/Strings.resx | Adds name/common-name/description/error message resources for the new rule. |
| Rules/MissingTryBlock.cs | Implements AST-based detection and emits diagnostics for missing try before catch/finally. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…iptAnalyzer into #2098MissingTryBlock
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
PR Summary
Although #2098 didn't get an up-for-graps label, I did create the suggested Add new MissingTryBlock rule to warn when catch or finally blocks are not preceded by a try block because:
catchblock that misses atryblock is less valid than atryblock that misses acatchblock which causes an parse error by the enginetryblock might easily get unnoticed during design time but will very likely fail during runtimetryblockPR Checklist
.cs,.ps1and.psm1files have the correct copyright headerWIP:to the beginning of the title and remove the prefix when the PR is ready.